package com.example.demo.service;

import com.example.demo.dao.TableOne;
import com.example.demo.dao.TableThree;
import com.example.demo.dao.TableTwo;
import com.example.demo.pojo.Table;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: DataMigrationService
 * @Description：
 * @Author: wanghr
 * Date: 3:52 PM 2020/2/27
 * Version: 1.0
 */
@Service
public class DataMigrationService {
    @Autowired
    private TableOne tableOne;
    @Autowired
    private TableTwo tableTwo;
    @Autowired
    private TableThree tableThree;

    //数据迁移
    public void dataMigration() {

        //获取表1中的数据
        List<Table> tablelist = tableOne.findAll();
        System.out.println(tablelist);
        //获取表2中某一字段
        for (Table table : tablelist) {
            String couple = tableTwo.findCoupleByNum(table);
            //获得完整table
            table.setCouple(couple);
            //向表3中插入数据 单个插
            //tableThree.add(table);
        }
        //向表3中插入数据 集合插
        Integer integer = tableThree.addList(tablelist);
        System.out.println("数据迁移成功");
    }

    //删除表3中所有数据
    public void deleteTab3() {
        Integer integer = tableThree.deleteAll();
        System.out.println("integer = " + integer);
    }
    //1111
    //222
    //3333
}
